# -*- coding: utf-8 -*-
from __future__ import print_function, division

#系统库
import os
import sys
#第三方库
import tornado.ioloop
import tornado.web
#自定义库
cwd = os.getcwd()
sys.path.append(cwd)
import Serverlib
import Serverlib.webhandler
import Serverlib.comethandler


#主体
class Server(tornado.web.Application):
    def __init__(self):
        handlers = [
            (r"/game(?:/([^/]*))*", Serverlib.webhandler.GameHandler),
            (r"/comet(?:/([^/]*))*", Serverlib.comethandler.Handler),
            (r"/gamehall(?:/([^/]*))*", Serverlib.webhandler.GameHallHandler),
            (r"/user(?:/([^/]*))*", Serverlib.webhandler.UserHandler),
            (r"/?(.*)", Serverlib.webhandler.MainHandler),
        ]
        settings = dict(
            debug=True,
            cookie_secret="agotskkfaw890U)@(*&*HkjklhJKLF;DJASDJijfpaijsf1",
            login_url="/login",
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            template_path=os.path.join(os.path.dirname(__file__), "template"),
        )
        tornado.web.Application.__init__(self, handlers, **settings)


def start():
    application = Server()
    application.listen(8080)
    tornado.ioloop.IOLoop.instance().start()

if __name__ == '__main__':
    start()
